# -!- coding: utf-8 -!-
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#作者：cacho_37967865
#博客：https://blog.csdn.net/sinat_37967865
#文件：geventTask.py
#日期：2019-11-19
#备注：gevent是第三方库，通过greenlet实现协程    pip install wheel  pip install gevent
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
import time
import gevent
import requests
from interfacetest.baseset.appsvr_api import API_APPSVR
from gevent import monkey; monkey.patch_all()

from logger import Logger
logger = Logger("geventModel").get_log()

url = 'https://test.zxtouch.msxiaodai.com'
headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36',
            'content-Type': 'application/json'
        }

def userInfo():
    fu_url = url + '/app/userInfo'
    data = API_APPSVR['submission']
    data['usrNo'] = 'YH20190902000002'
    req1 = requests.post(fu_url, json=data, headers=headers)
    data = req1.text
    print(data)


def gevent_task(g):
    begin_time = time.time()
    run_gevent_list = [gevent.spawn(userInfo) for g in range(g)]
    gevent.joinall(run_gevent_list)
    end = time.time()
    print('gevent协程累计测试时间 %.2f s'%(end - begin_time))


if __name__ == '__main__':
    gevent_task(100)